
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>动画 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Image-processing.html" />
    
    
    <link rel="prev" href="Multi-thread.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    关于
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Part I</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="Data-structure.html">
            
                <a href="Data-structure.html">
            
                    
                    数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="Arithmetic.html">
            
                <a href="Arithmetic.html">
            
                    
                    算法
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Part II</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="Foundation.html">
            
                <a href="Foundation.html">
            
                    
                    Foundation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="UIKit.html">
            
                <a href="UIKit.html">
            
                    
                    UIKit
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="WebView.html">
            
                <a href="WebView.html">
            
                    
                    WebView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="Memory-management.html">
            
                <a href="Memory-management.html">
            
                    
                    内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="Message-passing.html">
            
                <a href="Message-passing.html">
            
                    
                    消息传递的方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="Network.html">
            
                <a href="Network.html">
            
                    
                    网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="Data-storage.html">
            
                <a href="Data-storage.html">
            
                    
                    数据存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="Multi-thread.html">
            
                <a href="Multi-thread.html">
            
                    
                    多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="3.9" data-path="Animation.html">
            
                <a href="Animation.html">
            
                    
                    动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="Image-processing.html">
            
                <a href="Image-processing.html">
            
                    
                    图像处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="Data-encryption.html">
            
                <a href="Data-encryption.html">
            
                    
                    数据安全及加密
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="Runtime.html">
            
                <a href="Runtime.html">
            
                    
                    Runtime
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="Runloop.html">
            
                <a href="Runloop.html">
            
                    
                    Runloop
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Part III</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="Project-organization.html">
            
                <a href="Project-organization.html">
            
                    
                    项目架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="Design-patterns.html">
            
                <a href="Design-patterns.html">
            
                    
                    设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="Component-based.html">
            
                <a href="Component-based.html">
            
                    
                    组件化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="Debug-tips.html">
            
                <a href="Debug-tips.html">
            
                    
                    调试技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="Performance-optimization.html">
            
                <a href="Performance-optimization.html">
            
                    
                    性能优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="Source-code.html">
            
                <a href="Source-code.html">
            
                    
                    源码理解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="Code-management.html">
            
                <a href="Code-management.html">
            
                    
                    代码管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="Continuous-integration.html">
            
                <a href="Continuous-integration.html">
            
                    
                    持续集成
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >动画</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x52A8;&#x753B;">&#x52A8;&#x753B;</h1>
<h2 id="1uiview&#x52A8;&#x753B;&#x4E0E;&#x6838;&#x5FC3;&#x52A8;&#x753B;&#x7684;&#x533A;&#x522B;">1.UIView&#x52A8;&#x753B;&#x4E0E;&#x6838;&#x5FC3;&#x52A8;&#x753B;&#x7684;&#x533A;&#x522B;?</h2>
<ul>
<li>&#x6838;&#x5FC3;&#x52A8;&#x753B;&#x53EA;&#x4F5C;&#x7528;&#x5728;layer. </li>
<li>&#x6838;&#x5FC3;&#x52A8;&#x753B;&#x4FEE;&#x6539;&#x7684;&#x503C;&#x90FD;&#x662F;&#x5047;&#x50CF;.&#x5B83;&#x7684;&#x771F;&#x5B9E;&#x4F4D;&#x7F6E;&#x6CA1;&#x6709;&#x53D1;&#x751F;&#x53D8;&#x5316;.</li>
<li>&#x5F53;&#x9700;&#x8981;&#x4E0E;&#x7528;&#x6237;&#x8FDB;&#x884C;&#x4EA4;&#x4E92;&#x65F6;&#x7528;UIView&#x52A8;&#x753B;,&#x4E0D;&#x9700;&#x8981;&#x4E0E;&#x7528;&#x6237;&#x8FDB;&#x884C;&#x4EA4;&#x4E92;&#x65F6;&#x4E24;&#x4E2A;&#x90FD;&#x53EF;&#x4EE5;.</li>
</ul>
<h2 id="2&#x5F53;&#x6211;&#x4EEC;&#x8981;&#x505A;&#x4E00;&#x4E9B;&#x57FA;&#x4E8E;-calayer-&#x7684;&#x52A8;&#x753B;&#x65F6;&#xFF0C;&#x6709;&#x65F6;&#x9700;&#x8981;&#x8BBE;&#x7F6E;-layer-&#x7684;&#x951A;&#x70B9;&#x6765;&#x914D;&#x5408;&#x52A8;&#x753B;&#xFF0C;&#x8FD9;&#x65F6;&#x5019;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x4EC0;&#x4E48;&#xFF1F;">2.&#x5F53;&#x6211;&#x4EEC;&#x8981;&#x505A;&#x4E00;&#x4E9B;&#x57FA;&#x4E8E; CALayer &#x7684;&#x52A8;&#x753B;&#x65F6;&#xFF0C;&#x6709;&#x65F6;&#x9700;&#x8981;&#x8BBE;&#x7F6E; layer &#x7684;&#x951A;&#x70B9;&#x6765;&#x914D;&#x5408;&#x52A8;&#x753B;&#xFF0C;&#x8FD9;&#x65F6;&#x5019;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x4EC0;&#x4E48;&#xFF1F;</h2>
<ul>
<li><p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#x8BBE;&#x7F6E;&#x951A;&#x70B9;&#x4F1A;&#x5F15;&#x8D77;&#x539F;&#x6765; position &#x7684;&#x53D8;&#x5316;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x53D1;&#x751F;&#x4E0D;&#x7B26;&#x5408;&#x9884;&#x671F;&#x7684;&#x884C;&#x4E3A;&#xFF0C;&#x6240;&#x4EE5;&#x8981;&#x505A;&#x4E00;&#x4E0B;&#x8F6C;&#x5316;&#xFF0C;&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-c">  <span class="hljs-comment">// &#x4E3A; layer &#x7684;&#x52A8;&#x753B;&#x8BBE;&#x7F6E;&#x4E0D;&#x540C;&#x7684; anchor point&#xFF0C;&#x4F46;&#x662F;&#x53C8;&#x4E0D;&#x60F3;&#x6539;&#x53D8; view &#x539F;&#x6765;&#x7684; position&#xFF0C;&#x5219;&#x9700;&#x8981;&#x505A;&#x4E00;&#x4E9B;&#x8F6C;&#x6362;&#x3002;</span>
  - (<span class="hljs-keyword">void</span>)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view {
      <span class="hljs-comment">// &#x5206;&#x522B;&#x8BA1;&#x7B97;&#x539F;&#x6765;&#x951A;&#x70B9;&#x548C;&#x5C06;&#x66F4;&#x65B0;&#x7684;&#x951A;&#x70B9;&#x5BF9;&#x5E94;&#x7684;&#x5750;&#x6807;&#x70B9;&#xFF0C;&#x8FD9;&#x4E9B;&#x5750;&#x6807;&#x70B9;&#x662F;&#x76F8;&#x5BF9;&#x8BE5; view &#x5185;&#x90E8;&#x5750;&#x6807;&#x7CFB;&#x7684;&#x3002;</span>
      CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x,
                                     view.bounds.size.height * view.layer.anchorPoint.y);
      CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x,
                                     view.bounds.size.height * anchorPoint.y);

      <span class="hljs-comment">// &#x5982;&#x679C;&#x5F53;&#x524D; view &#x6709;&#x505A;&#x8FC7; transform&#xFF0C;&#x8FD9;&#x91CC;&#x8981;&#x540C;&#x6B65;&#x8BA1;&#x7B97;&#x3002;</span>
      oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform);
      newPoint = CGPointApplyAffineTransform(newPoint, view.transform);

      <span class="hljs-comment">// position &#x662F;&#x5F53;&#x524D; view &#x7684; anchor point &#x5728;&#x5176;&#x7236; view &#x7684;&#x4F4D;&#x7F6E;&#x3002;</span>
      CGPoint position = view.layer.position;
      <span class="hljs-comment">// anchor point &#x7684;&#x6539;&#x53D8;&#x4F1A;&#x9020;&#x6210; position &#x7684;&#x6539;&#x53D8;&#xFF0C;&#x4ECE;&#x800C;&#x5F71;&#x54CD; view &#x5728;&#x5176;&#x7236; view &#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x8FD9;&#x91CC;&#x628A;&#x8FD9;&#x4E2A;&#x4F4D;&#x79FB;&#x7ED9;&#x8BA1;&#x7B97;&#x56DE;&#x6765;&#x3002;</span>
      position.x = position.x + newPoint.x - oldPoint.x;
      position.y = position.y + newPoint.y - oldPoint.y;

      view.translatesAutoresizingMaskIntoConstraints = YES;
      view.layer.anchorPoint = anchorPoint; <span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x4E86;&#x65B0;&#x7684; anchor point &#x4F1A;&#x6539;&#x53D8;&#x4F4D;&#x7F6E;&#x3002;</span>
      view.layer.position = position; <span class="hljs-comment">// &#x901A;&#x8FC7;&#x5728; position &#x4E0A;&#x505A;&#x9006;&#x5411;&#x504F;&#x79FB;&#xFF0C;&#x628A;&#x4F4D;&#x7F6E;&#x7ED9;&#x79FB;&#x56DE;&#x6765;&#x3002;</span>
  }
</code></pre>
</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Multi-thread.html" class="navigation navigation-prev " aria-label="Previous page: 多线程">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Image-processing.html" class="navigation navigation-next " aria-label="Next page: 图像处理">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"动画","level":"3.9","depth":1,"next":{"title":"图像处理","level":"3.10","depth":1,"path":"Image-processing.md","ref":"Image-processing.md","articles":[]},"previous":{"title":"多线程","level":"3.8","depth":1,"path":"Multi-thread.md","ref":"Multi-thread.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"Animation.md","mtime":"2020-04-13T10:23:32.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-05-27T09:12:21.691Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

